//
//  ViewController.m
//  02-HomeWork
//
//  Created by dllo on 16/7/15.
//  Copyright © 2016年 danming. All rights reserved.
//

#import "ViewController.h"
#import "ForgetCodeViewController.h"
#import "RegisterViewController.h"
@interface ViewController ()<UITextFieldDelegate>
@property (nonatomic, strong) UIButton *userButton;
@property (nonatomic, strong) UIButton *passWordButton;
@property (nonatomic, strong) UITextField *userTextField;
@property (nonatomic, strong) UITextField *passWordTextField;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createCover];
}

#pragma mark - 博客地址     http://www.jianshu.com/users/455879dbdd0c/latest_articles
#pragma mark - 创建封面
- (void)createCover {
    /*********** 创建背景图片 ***********/
    UIImageView *backGroundImage = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    backGroundImage.image = [UIImage imageNamed:@"welcome_2"];
    [self.view addSubview:backGroundImage];
    /************ 创建logo *************/
    UIImageView *logoImage = [[UIImageView alloc] initWithFrame:CGRectMake(157, 120, 100, 160)];
    logoImage.image = [UIImage imageNamed:@"logo_lagou"];
    [backGroundImage addSubview:logoImage];
    /********** 创建两个textField下面的UIView ************/
    UIView *backGroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 320, 394, 81)];
    [self.view addSubview:backGroundView];
    /************ 创建两个TextField ************/
    self.userTextField = [[UITextField alloc] initWithFrame:CGRectMake(40, 0, 354, 40)];
    self.passWordTextField = [[UITextField alloc] initWithFrame:CGRectMake(40, 41, 354, 40)];
    _userTextField.tag = 1;
    _passWordTextField.tag = 2;
    _userTextField.backgroundColor = [UIColor blackColor];
    _passWordTextField.backgroundColor = [UIColor blackColor];
    _userTextField.alpha = 0.4f;
    _passWordTextField.alpha = 0.4f;
    _userTextField.textColor = [UIColor cyanColor];
    _passWordTextField.textColor = [UIColor cyanColor];
    _userTextField.delegate = self;
    _passWordTextField.delegate = self;
    [backGroundView addSubview:_userTextField];
    [backGroundView addSubview:_passWordTextField];
    
    /********** 创建两个button ********/
   self.userButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.passWordButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _userButton.frame = CGRectMake(0, 0, 40, 40);
    _passWordButton.frame = CGRectMake(0, 41, 40, 40);
    [_userButton setImage:[UIImage imageNamed:@"icon_username"] forState:UIControlStateNormal];
    [_passWordButton setImage:[UIImage imageNamed:@"icon_password"] forState:UIControlStateNormal];
    _userButton.tag = 11;
    _passWordButton.tag = 22;
    _userButton.backgroundColor = [UIColor blackColor];
    _passWordButton.backgroundColor = [UIColor blackColor];
    [backGroundView addSubview:_userButton];
    [backGroundView addSubview:_passWordButton];

    // 用贝塞尔曲线画圆角
    UIBezierPath *userBezier = [UIBezierPath bezierPathWithRoundedRect:_userTextField.bounds byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *userLayer = [[CAShapeLayer alloc] init];
    userLayer.frame = _userTextField.bounds;
    userLayer.path = userBezier.CGPath;
    _userTextField.layer.mask = userLayer;

    UIBezierPath *passWordBezier = [UIBezierPath bezierPathWithRoundedRect:_passWordTextField.bounds byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *passWordLayer = [[CAShapeLayer alloc] init];
    passWordLayer.frame = _passWordTextField.bounds;
    passWordLayer.path = passWordBezier.CGPath;
    _passWordTextField.layer.mask = passWordLayer;
    
    UIBezierPath *userButtonBezier = [UIBezierPath bezierPathWithRoundedRect:_userButton.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *userButtonLayer = [[CAShapeLayer alloc] init];
    userButtonLayer.frame = _userButton.bounds;
    userButtonLayer.path = userButtonBezier.CGPath;
    _userButton.layer.mask = userButtonLayer;
    
    UIBezierPath *passWordButtonBezier = [UIBezierPath bezierPathWithRoundedRect:_passWordButton.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *passWordButtonLayer = [[CAShapeLayer alloc] init];
    passWordButtonLayer.frame = _passWordButton.bounds;
    passWordButtonLayer.path = passWordButtonBezier.CGPath;
    _passWordButton.layer.mask = passWordButtonLayer;
    /********* 创建四个button ********/
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *forgetCodeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *nowRegisterButton = [UIButton buttonWithType:UIButtonTypeSystem];
    UIButton *strollButton = [UIButton buttonWithType:UIButtonTypeSystem];
    // 给button赋予颜色
    [forgetCodeButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [strollButton setTitle:@"随便逛逛>" forState:UIControlStateNormal];
    [nowRegisterButton setTitle:@"现在注册拉勾" forState:UIControlStateNormal];
    // 设置button的frame属性
    loginButton.frame = CGRectMake(15, 440, 384, 40);
    forgetCodeButton.frame = CGRectMake(10, 510, 100, 40);
    nowRegisterButton.frame = CGRectMake(132, 565, 150, 40);
    strollButton.frame = CGRectMake(157, 650, 100, 40);
    // 设置button的背景颜色以及文字样式和颜色
    loginButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    loginButton.tintColor = [UIColor lightGrayColor];
    forgetCodeButton.tintColor = [UIColor lightGrayColor];
    strollButton.tintColor = [UIColor lightGrayColor];
    nowRegisterButton.tintColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:50];
    // button的字体加粗
    forgetCodeButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    nowRegisterButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    strollButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    loginButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    // 设置button的圆角
    loginButton.layer.cornerRadius = 5;
    //添加button到view上
    [self.view addSubview:loginButton];
    [self.view addSubview:forgetCodeButton];
    [self.view addSubview:nowRegisterButton];
    [self.view addSubview:strollButton];
    // 给button添加点击事件
    [forgetCodeButton addTarget:self action:@selector(clickForgetCodeButton:) forControlEvents:UIControlEventTouchUpInside];
    [nowRegisterButton addTarget:self action:@selector(clickNowRegisterButton:) forControlEvents:UIControlEventTouchUpInside];
    /*********** 创建label及两个view **************/
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(196, 615, 20, 20)];
    label.text = @"or";
    label.font = [UIFont systemFontOfSize:20];
    label.textColor = [UIColor whiteColor];
    [self.view addSubview:label];
    // 创建高度为1的UIView
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(10, 625, 160, 1.5)];
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(235, 625, 160, 1.5)];
    leftView.backgroundColor = [UIColor whiteColor];
    rightView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:leftView];
    [self.view addSubview:rightView];
    
}

#pragma mark - 实现点击方法
- (void)clickForgetCodeButton:(UIButton *)button {
    ForgetCodeViewController *forget = [[ForgetCodeViewController alloc] init];
    forget.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:forget animated:YES completion:nil];
}

- (void)clickNowRegisterButton:(UIButton *)button {
    RegisterViewController *registerView = [[RegisterViewController alloc] init] ;
    registerView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:registerView animated:YES completion:nil];
}

#pragma mark - 变色效果
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        [_userButton setImage:[UIImage imageNamed:@"icon_username_select"] forState:UIControlStateNormal];
    } else {
        [_passWordButton setImage:[UIImage imageNamed:@"icon_password_select"] forState:UIControlStateNormal];
        
    }
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        [_userButton setImage:[UIImage imageNamed:@"icon_username"] forState:UIControlStateNormal];
    } else {
        [_passWordButton setImage:[UIImage imageNamed:@"icon_password"] forState:UIControlStateNormal];
    }

    return YES;
}
#pragma mark - 实现点击return键盘回收
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
#pragma mark - 实现点击空白出键盘回收
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}











- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
